
/**
 * @file main
 *
 */

 /*********************
  *      INCLUDES
  *********************/
#include <stdlib.h>
#include <unistd.h>


#include "lvgl/lvgl.h"
#include "lvgl/demos/widgets/lv_demo_widgets.h"
#include "lv_drivers/win32drv/win32drv.h"

#include <windows.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

  // #include "ui/ui.h"


#include <time.h>







#include <iostream>



#include "gui/inc/page.h"
#include "gui/inc/button.h"
#include "gui/inc/switch.h"
#include "gui/inc/button_switch.h"


  // #include "ui/ui_begin/ui_begin.h"
  // #include "ui/main_page/main_page.h"
  // #include "ui/control_page/control_page.h"
  // #include "ui/apps_page/apps_page.h"

#include "desktop/desktop.h"



#if(API_VERSION_CODE < 250301||API_VERSION_CODE > 250401)
#pragma warning("API version is not supported,please uchoose the right version")
#endif



pthread_mutex_t  display_mutex; // 初始化互斥锁







static void hal_init(void);

#define WINDOW_WIDTH     240
#define WINDOW_HEIGTH     280




/**********************
 *   GLOBAL FUNCTIONS
 **********************/
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow)
{




  lv_init();

  // HINSTANCE hInstance = *(HINSTANCE*) args;

  /*Initialize the HAL for LittlevGL*/
  lv_win32_init(hInstance, SW_SHOWNORMAL, WINDOW_WIDTH, WINDOW_HEIGTH, NULL);


  LV_LOG_USER("LVGL initialization completed!");


  // ui_init();



  // lv_obj_add_event_cb(ui_WifiSwitch, wifi_btn_pressed_cb, LV_EVENT_PRESSED, NULL);






  // printf("WinMain\n");
  // printf("1234");
  // printf("\b\b");


  desktop_init();




  // ui_begin_init();

  // Page* main_page = new MainPage();
  // Page* control_page = new ControlPage();
  // Page* apps_page = new AppsPage();



  pthread_mutex_init(&display_mutex, NULL);

  while (!lv_win32_quit_signal) {
    /* Periodically call the lv_task handler.
     * It could be done in a timer interrupt or an OS task too.*/
    pthread_mutex_lock(&display_mutex);    //上锁
    lv_task_handler();
    pthread_mutex_unlock(&display_mutex);   //关锁
    usleep(10000);       /*Just to let the system breath*/
  }
  return 0;



}



